<?php

/**
 * ECSHOP 视频
 * ============================================================================
 * 版权所有 2005-2010 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: article.php 16455 2009-07-13 09:57:19Z liubo $
*/

define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');

$act = !empty($_GET['act']) ? $_GET['act'] : '';
//if ($_SESSION['user_id'] > 0)
//{
//	$smarty->assign('user_name', $_SESSION['user_name']);
//
//}
if (!function_exists("htmlspecialchars_decode"))
{
	function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
	{
		return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
	}
}

/*文章列表请求*/

 else if ($act == 'get_list'){
 	$pageNo = !empty($_REQUEST['pageNo']) ? intval($_REQUEST['pageNo']) : 1;
	
	$pageSize=!empty($_REQUEST['pageSize'])?intval($_REQUEST['pageSize']) :10;
				
	$sql = " select a.title,a.description,a.click_count,a.article_id,a.add_time,a.img_url,ac.cat_name,cr.copyright_type from " . $ecs->table('article') . ' AS a LEFT JOIN '
				 . $ecs->table('article_cat') . ' AS ac ON a.cat_id= ac.cat_id LEFT JOIN '. $ecs->table('copyright') . ' AS cr ON a.copyright_id = cr.copyright_id'; 
	$sql .= " WHERE a.is_open = 1 AND ac.show_type = 3 ";
	$sql .= " ORDER BY a.add_time desc ";
	$sql .= " limit " .($pageNo-1)*$pageSize." ,".$pageSize;
	
	$row =$GLOBALS['db']->getAll($sql);
//	var_dump($row);

	$video_array = array();
	foreach ($row as $key => $video_data)
	{
		$video_array[$key]['title'] = $video_data['title'];
		$video_array[$key]['description'] = $video_data['description'];		
		$video_array[$key]['vid'] = $video_data['article_id'];		
		$video_array[$key]['click_count'] = $video_data['click_count'];				
		$video_array[$key]['cat_name'] = $video_data['cat_name'];				
		$video_data['copyright_type'] == 1 ? $video_array[$key]['is_original'] = 1 : $video_array[$key]['is_original'] = 0;				
		//文章时间
		$video_array[$key]['add_time']=local_date('Y-m-d H:i', $video_data['add_time']);			
		$video_array[$key]['imageUrl'] = OSS_HOST.get_image_path($video_data['article_id'],$video_data['img_url'],false,'artile');
//		$article_array[$key]['ImageUrl'] = getSignedUrlForGettingObject($ossClient, $bucket, OSS_HOST,get_image_path($article_data['article_id'],$article_data['file_url'],false,'artile'));
	}
	echo json_encode($video_array);
	
		
 }
/*文章内容请求*/
 else if ($act == 'get_info'){

 	$nid = !empty($_REQUEST['nid']) ? intval($_REQUEST['nid']) : '';

	if ($nid > 0)
	{
		$article_row = $GLOBALS['db']->getrow('SELECT title,link FROM ' . $ecs->table('article') . ' WHERE article_id = ' . $nid . ' AND is_open = 1');		
		if (!empty($article_row))
		{
			$result['title'] = $article_row['title'];						
			$result['url'] = $article_row['link'];									

//			$article_row['add_time']=local_date('Y-m-d H:i', $article_row['add_time']);

			/* 更新点击次数 */
			$db->query('UPDATE ' . $ecs->table('article') . " SET click_count = click_count + 1 WHERE article_id = '$nid'");
		}
	}
	echo json_encode($result);

	
 }

?>